package com.tangkun.environment.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.tangkun.environment.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 邀请对话框
 *
 * @author TangKun
 */
public class InvitationDialog extends Dialog {
    @BindView(R.id.tv_invitation_content)
    TextView tvInvitationContent;
    @BindView(R.id.btn_invitation_refuse)
    Button btnInvitationRefuse;
    @BindView(R.id.btn_invitation_accept)
    Button btnInvitationAccept;
    private Context context;
    private View view;

    public InvitationDialog(Context context) {
        super(context, R.style.InvitationDialogStyle);
        this.context = context;
        view = initView();
    }

    public InvitationDialog(Context context, int width, int height) {
        super(context, R.style.InvitationDialogStyle);
        this.context = context;
        view = initView();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_ACTION_BAR);
        requestWindowFeature(Window.PROGRESS_INDETERMINATE_ON);
        super.onCreate(savedInstanceState);
        DisplayMetrics dm = new DisplayMetrics();
        getWindow().getWindowManager().getDefaultDisplay().getMetrics(dm);
        getWindow().setWindowAnimations(R.style.InvitationDialogStyle);
        view = initView();
        RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(dm.widthPixels, dm.heightPixels);
        addContentView(view, lp);
        setCanceledOnTouchOutside(true);
    }


    private View initView() {
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_invitation, null);
        ButterKnife.bind(this, view);
        return view;
    }

    /***
     * 接受监听事件
     * */
    public InvitationDialog setOnAcceptClickedListener(LinearLayout.OnClickListener clickListener) {
        btnInvitationAccept.setOnClickListener(clickListener);
        return this;
    }

    /***
     * 拒绝监听事件
     * */
    public InvitationDialog setOnRefuseClickedListener(LinearLayout.OnClickListener clickListener) {
        btnInvitationRefuse.setOnClickListener(clickListener);
        return this;
    }
}
